home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 6.9 KB | 196 lines | [TEXT/ttxt] |
- --<<<
- -- Filename:
- -- PAINTACC.SX
-
- -- Other Files Required:
- -- GAUGUIN.BMP bitmap image (400 x 300)
-
- -- Purpose:
- -- Intended to be a simple title which stores bitmaps in a separate library file.
- -- and includes an accessory which zooms the bitmap larger and smaller.
-
- -- Specialized Classes: ExtendableTitleContainer and ZoomAccessory
-
- -- Instructions to User:
- -- 1. Open this script. It will create three files:
- -- A title file called PAINTING.SXT
- -- A library file called PAINTING.SXL
- -- An accessory file called PAINTING.SXA
- -- 2. Quit ScriptX. Open the newly created title container PAINTING.SXT
- -- from the operating system. It should open up the title container and
- -- library container, and display the painting.
- -- 3. Choose "Open Accessory" from the File menu and open PAINTING.SXA.
- -- This should display "To zoom, move the mouse left or right", and allow
- -- you to zoom the picture larger or smaller. Click to remove the
- -- accessory
-
- -- Authors:
- -- Erik Neumann, Douglas Kramer
-
- ------------------------------------------------------------------------------
- -- CREATE THE TITLE **********************************************************
- ------------------------------------------------------------------------------
- -- Create the window
- global myWindow := new Window boundary: (new Rect x1: 0 y1: 40 x2: 400 y2: 300)
- myWindow.name := "Gauguin"
- show myWindow
-
- ------------------------------------------------------------------------------
- -- Create and append a TwoDShape to the window
- global myShape := new TwoDShape
- append myWindow myShape
-
- ------------------------------------------------------------------------------
- -- Define a subclass of TitleContainer
- class ExtendableTitleContainer (TitleContainer)
- end
-
- -- Get the objects from the accessory
- method addAccessory self {class ExtendableTitleContainer} accContainer -> (
- local accList := nextMethod self accContainer
-
- -- Add the @text item from the accessory to the frontmost window
- prepend accContainer.windowHoldingAccessory accList[@text]
- )
-
- -- Remove the objects from the accessory (Undo what addAccessory did)
- method removeAccessory self {class ExtendableTitleContainer} accContainer -> (
- local myText := chooseOne accContainer.windowHoldingAccessory \
- (v a -> isAKindOf v TextPresenter) 0
- if myText = undefined do exit with myText
- deleteOne accContainer.windowHoldingAccessory myText.target
- nextMethod self accContainer
- )
-
- -- Create the title container and add the window to it
- global tc := new ExtendableTitleContainer dir:theScriptDir path:"painting.sxt" \
- name:"Painting Title"
- append tc myWindow
-
- -- Define the title's startup action
- tc.startupAction := (tc ->
-
- -- Load all objects in title container
- forEach tc load undefined
-
- -- Get the painting library
- local myLC := chooseOne theOpenContainers \
- (v a -> v.name = "Painting Library") 0
-
- -- Assign the bitmap to the 2D shape’s target in the frontmost window
- tc.windows[1][1].target := myLC[1]
- )
-
- ------------------------------------------------------------------------------
- -- CREATE THE LIBRARY ********************************************************
- ------------------------------------------------------------------------------
-
- function getPict fileName -> (
- local myStream := getStream theScriptDir fileName @readable
- local myimage := importMedia theImportExportEngine myStream @image @dib \
- @bitmap colormap:defaultcolormap
- myimage
- )
-
- global p1 := getPict "GAUGUIN.BMP"
-
- ------------------------------------------------------------------------------
- -- Create the library, and append the picture to it
- -- Note that this library uses the title container tc defined previously
- global lc := new LibraryContainer dir:theScriptDir path:"painting.sxl" \
- name:"Painting Library" user:tc
- append lc p1
-
- -- Close the title container and then the library container
- close tc
- close lc
-
-
- ------------------------------------------------------------------------------
- -- CREATE THE ACCESSORY ******************************************************
- ------------------------------------------------------------------------------
- -- Create an accessory container which must be added by the user
- class ZoomAccessory (AccessoryContainer)
- instance variables
- mouseMoveInterest -- Only reason for these ivs is they
- mouseDownInterest -- hold onto objects so those objects
- windowHoldingAccessory -- can later be removed
- end
-
- -- Remove event interests MouseEvent classes
- method removeAccEventInterests self {class ZoomAccessory} interest event -> (
- if (self.mouseMoveInterest != undefined) do
- removeEventInterest self.mouseMoveInterest
- if (self.mouseDownInterest != undefined) do
- removeEventInterest self.mouseDownInterest
- )
-
- -- This method is needed only to change the number and order of arguments
- method callRemoveAccessory self {class ZoomAccessory} interest event -> (
- removeAccessory theTitleContainer self
- )
-
- -- Method called by addAccessory from the title
- method getAccessory self {class ZoomAccessory} -> (
- -- Locate the bitmap in the title
- self.windowHoldingAccessory := theTitleContainer.windows[1]
- local myShape := chooseOne self.windowHoldingAccessory \
- (v a -> isAKindOf v TwoDShape) 0
- local myBitmap := myShape.boundary
-
- -- Scale the image
- function scaleIt theTwoDShape interest event -> (
- if (event.screenCoords.x > 1) do (
- local myScale := 2 * event.screenCoords.x / theTwoDShape.width
- local myMatrix := scale (new TwoDMatrix) myScale myScale
- transform myBitmap myMatrix @mutate
- theTwoDShape.changed := true
- theTwoDShape.x := (theTwoDShape.presentedBy.width \
- - theTwoDShape.width)/2
- theTwoDShape.y := (theTwoDShape.presentedBy.height \
- - theTwoDShape.height)/2
- )
- )
-
- -- Set up the mouse move event
- self.mouseMoveInterest := new MouseMoveEvent
- self.mouseMoveInterest.authorData := myShape
- self.mouseMoveInterest.presenter := undefined
- self.mouseMoveInterest.device := new MouseDevice
- self.mouseMoveInterest.eventReceiver := scaleIt
-
- addEventInterest self.mouseMoveInterest
-
- -- Set up the mouse down event
- self.mouseDownInterest := new MouseDownEvent
- self.mouseDownInterest.authorData := self
- self.mouseDownInterest.presenter := undefined
- self.mouseDownInterest.device := new MouseDevice
- self.mouseDownInterest.eventReceiver := callRemoveAccessory
-
- addEventInterest self.mouseDownInterest
-
- -- Add text to the accessory
- local myText := new TextPresenter boundary:(new Rect x2:400 y2:20) \
- target:" To zoom, move mouse left or right. Click to stop."
- setDefaultAttr myText @alignment @center
-
- myText.fill := whitebrush
-
- -- Create the list to be returned by getAccessory
- local accList := new HashTable
- add accList @text myText
- accList
- )
-
- -- Remove the event interests when title is closed
- method terminate self {class ZoomAccessory} -> (
- removeAccEventInterests self undefined undefined
- nextMethod self
- )
-
- global ac := new ZoomAccessory dir:theScriptDir path:"painting.sxa" \
- name:"Painting Accessory"
- close ac
-
-